package 蓝桥真题.javaB组国赛真题;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class 最大相邻和 {
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    static final int N=100010;
    static int a[]=new int[N],dp[]=new int[N],n;
    public static void main(String[] ss) throws IOException {
           n=Integer.parseInt(br.readLine());
           ss=br.readLine().split(" ");
           for(int i=1;i<=n;i++){
               a[i]=Integer.parseInt(ss[i-1]);
           }
           int max=-0x7f7f7f7f;
           for(int i=1;i<=n;i++){
               dp[i]=a[i];
               if(dp[i-1]+a[i]>dp[i]){
                   dp[i]+=dp[i-1];
                   max=Math.max(max,dp[i]);
               }
           }
        System.out.println(max);
    }
}
